<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<%@ page import="com.msmall.base.util.ConstantDB" language="java"%>
<c:set var="AVALIABLE" value="<%=ConstantDB.AVALIABLE%>"></c:set>
<c:set var="UNAVALIABLE" value="<%=ConstantDB.UNAVALIABLE%>"></c:set>
<c:set var="REPLY" value="<%=ConstantDB.REPLY%>"></c:set>
<c:set var="UNREPLY" value="<%=ConstantDB.UNREPLY%>"></c:set>
<c:set var="REPLY" value="<%=ConstantDB.REPLY%>"></c:set>
<c:set var="UNREPLY" value="<%=ConstantDB.UNREPLY%>"></c:set>
<c:set var="FROM_TRANSFER" value="<%=ConstantDB.FROM_TRANSFER%>"></c:set>
<c:set var="FROM_ORIGINAL" value="<%=ConstantDB.FROM_ORIGINAL%>"></c:set>
<c:set var="COMMEND_TYPE_QUESTION" value="<%=ConstantDB.COMMEND_TYPE_QUESTION%>"></c:set>

<div class="que_module martop10">
	<div class="w740 fl">
		<c:choose>
			<c:when test="${not empty question}">
				<div class="qshowcontent">
					<dl class="qshowquesask">
						<dt>
							<span class="sHB666">
								<c:out value="${question.content}"/>
							</span>
							<br>
							提问者：<ms:user type="nickname" link="true" userid="${question.userid}" nickname="${question.nickname}" style="a2"></ms:user>
							&nbsp;&nbsp;&nbsp;提问时间：<fmt:formatDate value="${question.createTime}" pattern="yyyy-MM-dd HH:mm"/>
							&nbsp;&nbsp;&nbsp; 浏览次数：<c:out value="${question.clickAmount}"/>次
						</dt>
						<dd>
							<c:set var="authorizeRemove"><ms:question action="remove" id="${question.questionid}"></ms:question></c:set>
							<ms:commend type="${COMMEND_TYPE_QUESTION}" id="${question.questionid}"></ms:commend>
							<c:if test="${authorizeRemove eq true}">
								|<a href="<c:url value='/question/delQuestion.do?questionid=${question.questionid}'/>">删除</a>
							</c:if>
							<a class="but62" href="#">我来回答</a>
						</dd>
					</dl>
					<div class="qshowanswer">
					</div>
				</div>
				<div class="qlistques martop10">
					<div class="qlistquesnav">
						<p class="qlistquesnavbg">其他回答</p>
					</div>
				</div>
				<div class="qshowanswerdiv">
					<div id="div_question_answer_new" class="qshowanswer" style="display:none"></div>
					<c:forEach var="answer" items="${page.items}" varStatus="status">
						<c:choose>
							<c:when test="${answer.enabled == AVALIABLE}">
								<div class="qshowanswer">
									<dl class="qshowanswerdl tc">
										<dt><ms:user type="nickname" link="true" userid="${answer.userid}" nickname="${answer.nickname}"></ms:user></dt>
										<dd><fmt:formatDate value="${answer.createTime}" pattern="yyyy-MM-dd HH:mm"/></dd>
									</dl>
									<p class="qshowanswerp">
										<c:out value="${answer.content}"></c:out>
									</p>
								</div>
							</c:when>
							<c:otherwise>
							</c:otherwise>
						</c:choose>
					</c:forEach>
				</div>
				<div class="qlistques martop10">
					<div class="qlistquesnav">
						<p class="qlistquesnavbg">我来回答</p>
						<div id="div_question_answer_error" style="display:none"></div>
					</div>
				</div>
				<div class="qshowanswerdiv">
					<form id="f_new_question_answer" action="<c:url value='/question/answer.do' />" method="post">
						<input type="hidden" name="answer.questionid" value="${question.questionid}"/>
						<p class="tc">
						<textarea id="question_answer_content" name="answer.content" class="qshowanswerform"><c:out value='${answer.content}'/></textarea>
						</p>
					</form>
					<p class="padtop10">
						<input class="but62" type="button" onclick="javascript:ajaxSubmitFollow('f_new_question_answer', 'div_question_answer_error', 'div_question_answer_new', 'question_answer_content');" value="提交回答"/>
					</p>
				</div>
			</c:when>
			<c:otherwise>
				<tiles:insertDefinition name="html.klg.article.notexist"></tiles:insertDefinition>
			</c:otherwise>
		</c:choose>
	</div>
	<div class="w250 fr">
		<tiles:insertDefinition name="html.question.index.mother"></tiles:insertDefinition>
		<tiles:insertDefinition name="html.question.index.baby"></tiles:insertDefinition>
		<tiles:insertDefinition name="html.question.index.growcycle"></tiles:insertDefinition>
	</div>
</div>

<script>
function ajaxSubmitFollow(formid, errorid, newid, contentid){
	$("#"+errorid).html();
	$("#"+errorid).css("display", "none");
	$.ajax({
		type : "POST",
		url : $("#"+formid).attr('action'),
		data : $("#"+formid).serialize(),
		dataType:"xml", 
		timeout:20000,
		success : function(data){
			if($(data).find('result').text().toUpperCase().indexOf("TRUE") < 0){
				$("#"+errorid).html($(data).find('content').text());
				$("#"+errorid).css("display", "block");
			}else{
				var content = "<div class='paper700_follow_notice'>作者：<c:out value='${nickname}'/>&nbsp;&nbsp;&nbsp;"+ formatDate(new Date(), "yyyy-MM-dd HH:mm"); 
				content = content + "</div><div class='paper700_follow_content'>";
				content = content + "您的回复正等待审核....<br/><br/>";
				content = content + $("#"+contentid).val();
				content = content + "</div>";
				$("#"+newid).html(content);
				$("#"+newid).css("display", "block");
				$("#"+contentid).val('');
			}
		},
		error: function(){
		}
	});
}
</script>